<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>${postBase.name}</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <link href="${contextPath}/static/share/css/style.css" rel="stylesheet" type="text/css">

</head>

<body>
<input type="hidden" id="hiddenTime" value="${hiddenTime}"/>
<div class="wrapper">
    <div class="invit">
        ${postBase.content}
        <!--投票倒计时-->
        <div class="voter_wrap">
            <div class="voter">
                <h3>投票截止倒计时</h3>
                <div class="count-down"></div>
                <!--投票列表-->
                <div class="voter_box">
                    <ul class="voter_list clearfix">
                        <c:forEach var="n" items="${tpPostSubList}">
                            <li>
                                <img src="${n.cover}"/>
                                <div class="itemer">
                                    <p class="name">${n.name}</p>
                                    <c:if test="${null == hiddenTime || hiddenTime == ''}">
                                        <p class="ticket"><span class="cast casted"><i class="i-praise"></i>${n.count}票</span></p>
                                    </c:if>
                                    <c:if test="${null != hiddenTime && hiddenTime != ''}">
                                        <p class="ticket"><span class="cast"><i class="i-praise"></i>投票（${n.count}票）</span></p>
                                    </c:if>
                                </div>
                            </li>
                        </c:forEach>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="footer-fixed">
    <div class="download_wrap clearfix">
            <span class="fl"><img src="${contextPath}/static/share/images/logo.png"/>
                <i>亿奇娱乐 <br/> <span>在这里，撩演员，戳主创</span></i>
            </span>
        <a class="download-link fr" href="http://a.app.qq.com/o/simple.jsp?pkgname=com.liumai.yiciyuan">立即下载</a>
    </div>
</div>
<script type="text/javascript" src="${contextPath}/static/share/js/index.js"></script>
<script type="text/javascript" src="${contextPath}/static/share/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="${contextPath}/static/share/js/prompt.js"></script>
<script type="text/javascript">
    $(function () {
        /*倒计时*/
        var time = $('#hiddenTime').val();

        // 如果时间为空，代表投票已结束
        if (null == time || time == '') {
            $('.count-down').html('投票已结束');
        } else {
            ShowCountDown(time);
        }
    })

    function ShowCountDown(endDate) {
        counter();
        var timer = window.setInterval(counter, 1000);

        function counter() {
            var leftTime = timestamp(endDate);
            leftTime -= 1;
            if (leftTime < 0) { //倒计时结束
                clearInterval(timer);
                $(".count-down").html('<span>0</span><i>天</i><span>0</span><span>0</span><i>天</i><span>0</span><span>0</span><i>天</i><span>0</span><span>0</span><i>天</i>');

            } else {
                var time = timeChange(timestamp(endDate))/*,tArr =[]*/, Txt = "";
                for (var i = 0; i < time[0].length; i++) {
                    //tArr.push( time[0].substr(i,1) );
                    Txt += '<span>' + time[0].substr(i, 1) + '</span>'
                }
                Txt2 = '<i>天</i>'
                        + '<span>' + time[1].substr(0, 1) + '</span>'
                        + '<span>' + time[1].substr(1, 1) + '</span>'
                        + '<i>时</i>'
                        + '<span>' + time[2].substr(0, 1) + '</span>'
                        + '<span>' + time[2].substr(1, 1) + '</span>'
                        + '<i>分</i>'
                        + '<span>' + time[3].substr(0, 1) + '</span>'
                        + '<span>' + time[3].substr(1, 1) + '</span>'
                        + '<i>秒</i>';
                $(".count-down").html(Txt + Txt2);
            }
        }

    }
    /*时间戳*/
    function timestamp(endDate) {
        var now = new Date();
        var endDate = new Date(endDate);
        var leftTime = endDate.getTime() - now.getTime();
        var leftsecond = parseInt(leftTime / 1000);
        return leftsecond;
    }
    /*返回天，时，分，秒*/
    function timeChange(stamp) {
        var day = Math.floor(stamp / (60 * 60 * 24));
        var hour = time(Math.floor((stamp - day * 24 * 60 * 60) / 3600));
        var minute = time(Math.floor((stamp - day * 24 * 60 * 60 - hour * 3600) / 60));
        var second = time(Math.floor(stamp - day * 24 * 60 * 60 - hour * 3600 - minute * 60));
        return [day + '', hour + '', minute + '', second + ''];
    }
    /*时分秒小于10前面加0*/
    function time(i) {
        if (i < 10) {
            i = "0" + i;
        }
        return i;
    }
</script>
</body>
</html>